import KTToggle from "./toggle"
import KTSticky from "./sticky"
import KTDrawer from "./drawer";
import KTSwapper from "./swapper";
import KTMenu from "./menu";
import KTScroll from "./scroll";
import KTScrolltop from "./scrolltop";

const ToggleComponent = {
    bootstrap: () => KTToggle.createInstances(),
    reinitialization: () => KTToggle.createInstances(),
    createInstance: (selector) => KTToggle.createInstances(selector)
}

const StickyComponent = {
    bootstrap: () => {
        KTSticky.createInstances()
        KTSticky.initGlobalHandlers()
    },
    reinitialization: () => KTSticky.createInstances(),
    createInstance: (selector) => KTSticky.createInstances(selector)
}

const MenuComponent = {
    bootstrap: () => {
        KTMenu.createInstances()
        KTMenu.initGlobalHandlers()
    },
    reinitialization: () => KTMenu.createInstances(),
    createInstance: (selector) => KTMenu.createInstances(selector),
    hideDropdowns: (skip) => KTMenu.hideDropdowns(skip)
}

const ScrollComponent = {
    bootstrap: () => {
        KTScroll.createInstances()
        KTScroll.initGlobalHandlers()
    },
    reinitialization: () => KTScroll.createInstances(),
    createInstance: (selector) => KTScroll.createInstances(selector),
    updateAll: () => {
        const elements = document.body.querySelectorAll('[data-kt-scroll="true"]')
        elements.forEach((element) => {
            const instance = KTScroll.getInstance(element)
            if (instance) {
                instance.update()
            }
        })
    }
}

const DrawerComponent = {
    bootstrap: () => {
        KTDrawer.createInstances()
        KTDrawer.initGlobalHandlers()
        KTDrawer.handleShow()
        KTDrawer.handleDismiss()
    },
    reinitialization: () => {
        KTDrawer.createInstances()
        KTDrawer.hideAll()
        KTDrawer.updateAll()
        KTDrawer.handleShow()
        KTDrawer.handleDismiss()
    },
    createInstance: (selector) => KTDrawer.createInstances(selector)
}

const SwapperComponent = {
    bootstrap: () => {
        KTSwapper.createInstances()
        KTSwapper.initGlobalHandlers()
    },
    reinitialization: () => KTSwapper.createInstances(),
    createInstance: (selector) => KTSwapper.createInstances(selector)
}

const ScrollTopComponent = {
    bootstrap: () => KTScrolltop.createInstances(),
    reinitialization: () => KTScrolltop.createInstances(),
    createInstance: (selector) => KTScrolltop.createInstances(selector)
}

export {
    ToggleComponent,
    StickyComponent,
    MenuComponent,
    ScrollComponent,
    DrawerComponent,
    SwapperComponent,
    ScrollTopComponent
}